package com.client.task;

import android.content.Context;
import android.os.AsyncTask;

import com.client.bean.Call;
import com.client.bean.CallMessage;

public class CallMessagesTask extends AsyncTask<Call, Void, Integer> {
	public interface Callback {

		void onComplete(Integer result);
	}

	private final Context context;
	private Callback callback;

	public CallMessagesTask(Context context, Callback callback) {
		this.context = context;
		this.callback = callback;
	}

	/**
	 * The task should be executed with one given source photo uri.
	 */
	@Override
	protected Integer doInBackground(Call... params) {
		if (params[0] == null) {
			return 0;
		} else {
			if (!iscancle) {
				// for (int i = 0; i < 30; i++) {
				CallMessage mCallMessage1 = new CallMessage();
				mCallMessage1.name = "火警119";
				mCallMessage1.num = "119";
				params[0].addCallMessage(mCallMessage1);

				CallMessage mCallMessage2 = new CallMessage();
				mCallMessage2.name = "匪警110";
				mCallMessage2.num = "110";
				params[0].addCallMessage(mCallMessage2);

				CallMessage mCallMessage3 = new CallMessage();
				mCallMessage3.name = "急救 120";
				mCallMessage3.num = "120";
				params[0].addCallMessage(mCallMessage3);

				CallMessage mCallMessage4 = new CallMessage();
				mCallMessage4.name = "急救 999";
				mCallMessage4.num = "999";
				params[0].addCallMessage(mCallMessage4);

				CallMessage mCallMessage5 = new CallMessage();
				mCallMessage5.name = "交警 122";
				mCallMessage5.num = "122";
				params[0].addCallMessage(mCallMessage5);

				CallMessage mCallMessage6 = new CallMessage();
				mCallMessage6.name = "单位12345678";
				mCallMessage6.num = "12345678";
				params[0].addCallMessage(mCallMessage6);
				// }
			}
		}

		return 1;
	}

	@Override
	protected void onPostExecute(Integer result) {
		// if (result == null) {
		// Toast toast = Toast.makeText(context, R.string.loading_failure,
		// Toast.LENGTH_SHORT);
		// toast.setGravity(Gravity.CENTER, 0, 0);
		// toast.show();
		// }
		if (callback != null) {
			callback.onComplete(result);
		}

	}

	private boolean iscancle = false;

	public void release() {
		callback = null;
	}
}
